Topic: Bypass Temp Directory
I need to know how to bypass the temp directory when downloading a file. I know its possible because other web based ftp's do it.
|
Close Help |
You are not logged in. Please login or register.
I need to know how to bypass the temp directory when downloading a file. I know its possible because other web based ftp's do it.
The standard PHP function ftp_get() downloads the files from
the FTP server to the web server's /temp directory. There is no way
around using a local file, unless you write your own ftp_get function;
an example is posted on the PHP website - I didn't try it out:
http://www.php.net/manual/en/function.ftp-get.php#72603
the buffer in the socket pair is only about 364 bytes. So it doesn't work for files larger than that size.
Theres
gotta be another way... How to big file websites do this? They dont
move the file over to a temp directory first. This seems like it would
be easy, but its not.
Is there a way to create just a link to the ftp
with the user and pass? like
ftp://username:password@ftpserver.com/directory/file
That seems like it would be easy, but I'm not very good at php and I wouldn't know what to change.
Hi.
I writed a method, using custom headers and readfile function for read ftp file content. On filesystem.inc.php:
function ftp_downloadfile($directory, $entry) {
global $net2ftp_globals, $net2ftp_result, $net2ftp_settings;
$conn_id = ftp_openconnection();
if ($net2ftp_result["success"] == false) { return false; }
// Decrypt password
if (isset($_SESSION["net2ftp_password_encrypted_" . $net2ftp_globals["ftpserver"] . $net2ftp_globals["username"]]) == true) {
$net2ftp_password = decryptPassword($_SESSION["net2ftp_password_encrypted_" . $net2ftp_globals["ftpserver"] . $net2ftp_globals["username"]]);
} else {
$net2ftp_password = decryptPassword($net2ftp_globals["password_encrypted"]);
}
// Direct download
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"".$entry."\"");
readfile("ftp://".$net2ftp_globals["username"].":".
$net2ftp_password."@".
$net2ftp_globals["ftpserver"].":".
$net2ftp_globals["ftpserverport"].
$directory.$entry);
return false;
}
Maybe it'is not perfect, but it's faster and works for me
See ya
Last edited by daveruiz (2008-01-08 11:45:06)
Hi.
I writed a method, using custom headers and readfile function for read ftp file content. On filesystem.inc.php:
function ftp_downloadfile($directory, $entry) { global $net2ftp_globals, $net2ftp_result, $net2ftp_settings; $conn_id = ftp_openconnection(); if ($net2ftp_result["success"] == false) { return false; } // Decrypt password if (isset($_SESSION["net2ftp_password_encrypted_" . $net2ftp_globals["ftpserver"] . $net2ftp_globals["username"]]) == true) { $net2ftp_password = decryptPassword($_SESSION["net2ftp_password_encrypted_" . $net2ftp_globals["ftpserver"] . $net2ftp_globals["username"]]); } else { $net2ftp_password = decryptPassword($net2ftp_globals["password_encrypted"]); } // Direct download header("Content-type: application/force-download"); header("Content-Transfer-Encoding: Binary"); header("Content-disposition: attachment; filename=\"".$entry."\""); readfile("ftp://".$net2ftp_globals["username"].":". $net2ftp_password."@". $net2ftp_globals["ftpserver"].":". $net2ftp_globals["ftpserverport"]. $directory.$entry); return false; }
Maybe it'is not perfect, but it's faster and works for me
See ya
Thank you so much for the MOD, I was looking for something like this for long time !
All the best!
By far one of the most important and greatest snips of code to add into the FTP client. 100% amazing well done.
For people that dont know how to use this piece of code, go to the file he told you to edit, search the function and take out and replace the whole function code.
Works a treat
Now can someone write an upload equivalent to this?
Last edited by BLACKHAWK (2010-07-19 22:56:21)
Hello everyone,
Thank you for this great snip of code, I do have one question though: when I add this code, all files are downloaded as 0kb in size. Is there any workaround for this?
Thanks in advance,
Jim Morris
Hi everybody,
This is exactly what I need, but I have the same problem as JimMorris has, the dowloaded files are only 1kb and cannot be opened after dowloading. Any ideas?
Thanks and cheers !
Thank you for the funciton, i've noticed that the files are downloading in the right way only in the root ftp directory.
Using subfolders I have the same problem of the other people.
The issue is that the function you worte works correctly if you change the parameters in ftp_downloadfile
because $directory miss a '/' at the end of his name.
Solution:
In modules\downloadfile there is downloadfile.inc.php that contains only the following function
function net2ftp_module_sendHttpHeaders() {
// --------------
// This function sends HTTP headers
// --------------
global $net2ftp_globals, $net2ftp_settings;
if ($net2ftp_settings["functionuse_downloadfile"] == "yes") {
//replace
//ftp_downloadfile($net2ftp_globals["directory"], $net2ftp_globals["entry"]);
//with
ftp_downloadfile($net2ftp_globals["directory"]."/", $net2ftp_globals["entry"]);
//and that's all
}
else {
$errormessage = __("This function has been disabled by the Administrator of this website.");
setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
return false;
}
} // end net2ftp_sendHttpHeaders
Thanks a lot for enjoying this beauty article with me. I am appreciating it very much! Looking forward to another great article. Good luck to the author! all the best!
I am happy to find so many useful information here in the post, we need develop more strategies in this regard, thanks for sharing.
These kind of post are always inspiring and I prefer to read quality content so I happy to find many good point here in the post, writing is simply great, thank you for the post
Post is nicely written and it contains many good things for me. I am glad to find your impressive way of writing the post. Now it become easy for me to understand and implement the concept. Thanks for sharing the post.
Thanks for the nice blog. Keep sharing such ideas in the future as well. This was actually what I was looking for, and I am glad to came here! Thanks for sharing the such information with us
It argues that a Greek naval blockade during the Trojan War kept Trojans on the European shore from intervening, and that they subsequently escaped to Italy where they were called Etruscans.
I am delighted to find many useful things here, that's superb. Thanks for sharing
marble polishing stone cleaning
Luckily, I am here again as I thought I’ve lost everything.
Now, I am pretty much happy to enjoy your new posts and marvelous ideas
on the topics. Here my family is joining reading me.
seattle moving companies
You have a very interesting blog, thanks for sharing.
cheap escorts London
The article is really interesting and informative, thank you. toronto russian escort
What an interesting topic! Thanks for sharing it here toronto vip escort
The article is really interesting and informative, thank you. teen escort toronto
What an interesting topic! Thanks for sharing it here female escorts toronto
It's very good that I found this blog toronto escort service
Your info is appreciated,for I have been trying to know sth about it.Thank you.
Your info is appreciated,for I have been trying to know sth about it.Thank you. nike shox
Powered by PunBB, supported by Informer Technologies, Inc.
Currently installed 4 official extensions. Copyright © 2003–2009 PunBB.